package com.common.project.controller;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/***
 * @Title
 * @Author jiangshicun@bicai365.com
 * @Description session
 * @Date 10:56 2019/7/4
 * @Param
 * @return
 */
@Controller
@RequestMapping("/session")
public class SessionController {
    @ApiOperation(value = "设置session", notes = "返回值说明: ")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "value", value = "value", required = true,defaultValue ="")

    })
    @ResponseBody
    @GetMapping("/setsession")
    public String set(HttpServletRequest req){
        HttpSession session=req.getSession();
        session.setAttribute("value",req.getParameter("value"));
        return session.getId();
    }

    @ApiOperation(value = "获取session", notes = "返回值说明: ")
    @ResponseBody
    @GetMapping("/getsession")
    public Object query(HttpServletRequest req) {
        HttpSession session=req.getSession();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("SessionId", session.getId());
        map.put("value", session.getAttribute("value"));
        return map;
    }
}
